package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.BookModel;
import com.ruitu.health_2.ui.common.BookListActivity;
import com.ruitu.health_2.ui.fragment.ReadPartyBookFragment;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.product.Book;

import java.util.List;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class BookPresenter {

    public static class BookListP extends BasePresenter<BookListActivity, BookModel.BookListM> {

        public Disposable reqBookList(int size, int num) {
            return m.reqBookList(size, num).subscribe(new Consumer<BaseResult2<PageModel2<Book>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Book>> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }

        public Disposable reqBookListByColumn(String posId, int size, int num) {
            return m.reqBookListByColumn(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<Book>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Book>> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }

    public static class ReadPartyBookListP extends BasePresenter<ReadPartyBookFragment, BookModel.BookListM> {
        public Disposable reqReadPartyBookList(String id, String type) {
            return m.reqReadPartyBookStateList(id, type).subscribe(new Consumer<BaseResult2<List<Book>>>() {
                @Override
                public void accept(BaseResult2<List<Book>> result) throws Exception {
                    v.hideProgress();
                    if (result.isSuccess()) {
                        v.onReqComplete(1, true, result.getData());
                    } else {
                        ToastUtils.showShortSafe(result.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    throwable.printStackTrace();
                }
            });
        }
    }
}
